package com.example.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import com.example.activity.MaskActivity;
import com.example.smart_home.R;
import com.example.util.CommandCommunicate;
import com.example.util.ShowHandle;

public class MaskAdapter extends BaseAdapter
{
  private MaskActivity context;
  private ArrayList<String[]> lightList;
  private CommandCommunicate mCommandCommunicate;
  private ShowHandle showHandle;

  public MaskAdapter(Context paramContext)
  {
    this.context = ((MaskActivity)paramContext);
    this.showHandle = new ShowHandle(paramContext, "it");
    this.showHandle.OpenDb();
    this.lightList = this.showHandle.getDeviceMask(((Activity)paramContext).getIntent().getStringExtra("roomId"));
    this.showHandle.CloseDb();
    this.mCommandCommunicate = new CommandCommunicate(paramContext);
  }

  public int getCount()
  {
    return this.lightList.size();
  }

  public Object getItem(int paramInt)
  {
    return null;
  }

  public long getItemId(int paramInt)
  {
    return 0L;
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    LayoutInflater localLayoutInflater = (LayoutInflater)this.context.getSystemService("layout_inflater");
    String[] arrayOfString = (String[])this.lightList.get(paramInt);
    this.showHandle.OpenDb();
    final ArrayList<String[]> localArrayList = this.showHandle.getDeviceKey(arrayOfString[0]);
    this.showHandle.CloseDb();
    View localView = localLayoutInflater.inflate(R.layout.maskadapter, null);
    LinearLayout localLinearLayout1 = (LinearLayout)localView.findViewById(R.id.btnOpen);
    if ((arrayOfString[0] != null) && (!"".equals(arrayOfString[0])))
      localLinearLayout1.setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          MaskAdapter.this.mCommandCommunicate.send(((String[])localArrayList.get(0))[3]);
        }
      });
    LinearLayout localLinearLayout2 = (LinearLayout)localView.findViewById(R.id.btnClose);
    if ((arrayOfString[0] != null) && (!"".equals(arrayOfString[0])))
      localLinearLayout2.setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          MaskAdapter.this.mCommandCommunicate.send(((String[])localArrayList.get(1))[3]);
        }
      });
    ((TextView)localView.findViewById(R.id.tvMaskName)).setText(arrayOfString[1]);
    return localView;
  }
}
